<?php

namespace App\Admin\Controllers;

use App\crm_account;

use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Content;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\ModelForm;

class crm_accountController extends Controller
{
    use ModelForm;

    /**
     * Index interface.
     *
     * @return Content
     */
    public function index()
    {
        return Admin::content(function (Content $content) {

            $content->header('账户管理');
            $content->description('账户列表');

            $content->body($this->grid());
        });
    }

    /**
     * Edit interface.
     *
     * @param $id
     * @return Content
     */
    public function edit($id)
    {
        return Admin::content(function (Content $content) use ($id) {

            $content->header('header');
            $content->description('description');
            $content->body($this->form()->edit($id));
        });
    }

    /**
     * Create interface.
     *
     * @return Content
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header('账户管理');
            $content->description('账户添加');
            
            $content->body($this->form());
        });
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Admin::grid(crm_account::class, function (Grid $grid) {
            $grid->id('序号')->sortable();
            $grid->account_name('账户名称');
            $grid->account_type('账户类型');
            $grid->account_number('账户号');
            $grid->account_kaihu('开户行');
            $grid->disableBatchDeletion();  //把操作框干掉
            $grid->disableExport();         //把导出框干掉
            // $grid->disableCreation();       //把新增框干掉
            $grid->disableFilter();         //把搜索框干掉
            // $grid->created_at();
            // $grid->updated_at();
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Admin::form(crm_account::class, function (Form $form) {

            $form->display('id', '序号');
            $form->text('account_name','账户名称')->rules('required');
            $form->text('account_type','账户类型')->rules('required');
            $form->text('account_number','账户号')->rules('required');
            $form->text('account_kaihu','开户行');
            $form->tools(function (Form\Tools $tools) {
                // 去掉跳转列表按钮
                $tools->disableListButton();
            });
            // $form->display('created_at', 'Created At');
            // $form->display('updated_at', 'Updated At');
        });
    }
}
